package com.chuangyang.fixboxlib.widgets;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chuangyang.fixboxlib.R;


/**
 * Created by vanshu on 15/3/16.
 */
public class ListItemView extends LinearLayout {

    private void init(){
        setClickable(true);
        setFocusable(true);
    }


    private void drawView(Context context,AttributeSet attrs){
        TypedArray a = null;
        View view ;
        try {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.profile_list_item, this, true);
            ImageView listItemIcon = (ImageView) view.findViewById(R.id.list_item_icon);
            TextView listItemDescription = (TextView) view.findViewById(R.id.list_item_des);
            a = context.obtainStyledAttributes(attrs, R.styleable.ListItemView);
            Drawable  src = a.getDrawable(R.styleable.ListItemView_src);
            String description=a.getString(R.styleable.ListItemView_description);
            if(src!=null){
                listItemIcon.setVisibility(VISIBLE);
                listItemIcon.setImageDrawable(src);
            }
            if(description!=null){
                listItemDescription.setText(description);
            }

        } catch (Exception e) {
        } finally {
            if (a != null)
                a.recycle();
        }
    }


    public ListItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
        drawView(context,attrs);
    }
}
